package com.mmall.concurrency.example.immutable;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.Map;

@Slf4j
public class ImmutableExample2 {

    private static Map<Integer, Integer> map = Maps.newHashMap();

    static {
        map.put(1,2);
        map.put(3,4);
        map.put(5,6);
        map = Collections.unmodifiableMap(map);
    }

    public static void main(String[] args) {

        map.put(3,5);
        log.info("{}",map.get(3));

        /**
         * Exception in thread "main" java.lang.UnsupportedOperationException
         * 	at java.util.Collections$UnmodifiableMap.put(Collections.java:1457)
         * 	at com.mmall.concurrency.example.immutable.ImmutableExample2.main(ImmutableExample2.java:23)
         */
    }
}
